<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>会员广告列表</h4>
		<div class="bk10"></div>
		<div>
			<form class="form-inline">
				<div class="form-group form-group-sm">
					<label for="title">广告标题：</label>
					<input type="text" class="form-control" id="title" name="title" placeholder="标题" value="<{$title}>">
				</div>
				<div class="form-group form-group-sm">
					<label for="title">会员id：</label>
					<input type="text" class="form-control" id="uid" name="uid" placeholder="会员id：" value="<{$uid}>">
				</div>
				<div class="bk10"></div>
				<div class="form-group form-group-sm">
					<label for="start_time">创建时间：</label>
					<input type="text" class="form-control laydate-icon" id="start_time" name="start_time" onclick="laydate({istime:true, format:'YYYY-MM-DD hh:mm:ss'})" value="<{$start_time?($start_time|date='Y-m-d H:i:s',###):''}>">
					<span>-</span>
					<input type="text" class="form-control laydate-icon" id="end_time" name="end_time" onclick="laydate({istime:true, format:'YYYY-MM-DD hh:mm:ss'})" value="<{$end_time?($end_time|date='Y-m-d H:i:s',###):''}>">
				</div>
				<div class="form-group form-group-sm">
					<label for="sort">排序：</label>
					<select class="form-control" name="sort" id="sort">
						<foreach name="sortList" item="row">
							<option value="<{$key}>" <if condition="$key eq $sort">selected="selected"</if> ><{$row['name']}></option>
						</foreach>
					</select>
				</div>
				<div class="form-group form-group-sm">
					<label for="sort">广告类型：</label>
					<select class="form-control" name="type" id="sort">
							<option value="" <if condition="'' eq $type">selected="selected"</if>>全部类型</option>
							<option value="-1" <if condition="-1 eq $type">selected="selected"</if>>文字</option>
							<option value="1" <if condition="1 eq $type">selected="selected"</if>>图文</option>
							<option value="4" <if condition="4 eq $type">selected="selected"</if>>电话</option>
					</select>
				</div>
				<div class="bk10"></div>
				<?php /* Todo: 多表查询 或者 先异步查询用户得到ID再加入查询
				<div class="form-group form-group-sm">
					<label for="member_name">会员昵称：</label>
					<input type="text" class="form-control" id="member_name" name="member_name" placeholder="会员昵称" value="<{$member_name}>">
					<label for="member_phone">手机号码：</label>
					<input type="text" class="form-control" id="member_phone" name="member_phone" placeholder="手机号码" value="<{$member_phone}>">
				</div>
				<div class="bk10"></div>
				*/ ?>
				<div class="form-group form-group-sm">
					<label>广告审核状态：</label>
					<div class="checkbox">
						<label class="checkbox-inline">
							<input type="checkbox" id="statePassCheck" <if condition='$statePass'>checked=checked</if> >
							<input type="hidden" name="statePass" id="statePass" value="<{$statePass}>">
							<font color="green">可发布</font>
						</label>
						<label class="checkbox-inline">
							<input type="checkbox" id="stateVetoCheck" <if condition='$stateVeto'>checked=checked</if> >
							<input type="hidden" name="stateVeto" id="stateVeto" value="<{$stateVeto}>">
							<font color="red">禁止发布</font>
						</label>
					</div>
				</div>
				<button type="submit" class="btn btn-default btn-sm col-md-offset-1"><b>广告筛选</b></button>
			</form>
		</div>
		<div class="bk10"></div>
		<div class="btn-toolbar">
			<div class="btn-group btn-group-sm">
				<button type="button" id="sBtnAll" class="btn btn-default">全选</button>
				<button type="button" id="sBtnBut" class="btn btn-default">反选</button>
				<button type="button" id="sBtnNull" class="btn btn-default">不选</button>
			</div>
			<div class="btn-group btn-group-sm">
				<button type="button" onclick="selectPass()" class="btn btn-default">审核通过</button>
				<button type="button" onclick="selectVeto()" class="btn btn-default">审核否决</button>
			</div>
		</div>
		<table class="table table-bordered table-hover">
			<tr>
				<th><input type="checkbox" name="selectAll" id="selectAll"></th>
				<th>标题</th>
				<th>创建时间</th>
				<th>广告类型</th>
				<th>广告图片</th>
				<th>创建人</th>
				<th>创建人id</th>
				<th>状态</th>
				<th>操作</th>
			</tr>

			<empty name="list">
				<tr><td colspan="6" style="text-align:center;color:#999">～暂无数据～</td></tr>
			<else /> 

				<foreach name="list" item="vo">
					<tr>
						<td><input type="checkbox" name="batchId" class="batchId" value="<{$vo['id']}>" data-status="<{$vo['status']}>" ></td>
						<td><{$vo['title']}></td>
						<td><{$vo['createtime']|date="Y-m-d H:i",###}></td>
						<td>
							<eq name="vo['type']" value="0">文字广告</eq>
							<eq name="vo['type']" value="1">图文广告</eq>
							<eq name="vo['type']" value="4">电话广告</eq>
						</td>
						<td>
							<empty name="vo['thumb']">
								<img src="/Public/img/notimage.jpg"  style="width:100px;height:auto">
							<else />
								<img src="<{$vo['thumb']}>"  style="width:100px;height:auto">
							</empty>
						</td>
						<td>
							<{$vo['username']}> 
						</td>
						<td>
							<{$vo['uid']}> 
						</td>
						<td>
							<if condition="$vo['status'] eq 1">
								可发布
							<elseif condition="$vo['status'] eq -1"/>
								<font color="red">禁止发布</font>
							</if>
						</td>
						<td>
							<a href="<{:U('adEdit',array('id'=>$vo['id'],'k'=>2,'sk'=>2))}>">审核广告</a>
						</td>
					</tr>
				</foreach>
			
			</empty>
			
		</table>
		
		<div class="pagebar">
			<{$pager}>
		</div>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
$(function(){

	checkAllState();


	$('#stateWaitCheck').click(function() {
		if ($(this).prop('checked')) {
			$('#stateWait').val('1');
		} else {
			$('#stateWait').val('0');
		}
	});
	$('#statePassCheck').click(function() {
		if ($(this).prop('checked')) {
			$('#statePass').val('1');
		} else {
			$('#statePass').val('0');
		}
	});
	$('#stateVetoCheck').click(function() {
		if ($(this).prop('checked')) {
			$('#stateVeto').val('1');
		} else {
			$('#stateVeto').val('0');
		}
	});

	$('#sBtnAll').click(function() {
		$('.batchId').prop('checked', true);
		$('#selectAll').prop('checked', true);
	});

	$('#sBtnNull').click(function() {
		$('.batchId').prop('checked', false);
		$('#selectAll').prop('checked', false);
	});

	$('#sBtnBut').click(function() {
		$('.batchId').each(function(index, el) {
			if ($(this).prop('checked'))
			{
				$(this).prop('checked', false);
			}
			else
			{
				$(this).prop('checked', true);
			}
		});
		checkAllState();
	});

	$('.batchId').change(function() {
		checkAllState();
	});

	$('#selectAll').click(function() {
		$('.batchId').prop('checked', true);
		$('#selectAll').prop('checked', true);
	});
});

// 检查全选状态
function checkAllState()
{
	var allFalg = true;
	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked') === false)
		{
			allFalg = false;
		}
	});
	if (allFalg)
	{
		$('#selectAll').prop('checked', true);
	}
	else
	{
		$('#selectAll').prop('checked', false);
	}
}

// 批量通过选择项
function selectPass()
{
	var idArray = new Array;
	var subCount = 0;
	var subWait = 0;
	var subPass = 0;
	var subVeto = 0;

	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked')) {
			// alert($(this).attr('data-status'));
			subCount++;

			switch ($(this).attr('data-status'))
			{
				case '1':
					subPass++;
					break;
				case '-1':
					subVeto++;
					break;
			}
			idArray[index] = $(this).val();
		};
	});

	var tipsMsg = '您确定审核<font color="red">通过</font>所选的 '+subCount+' 广告？<br>其中：<font color="green">已通过</font>：'+subPass+'<br><font color="red">被否决</font>：'+subVeto+'<br>[请谨慎操作]';
	
	if (subCount) {
		layer.confirm(tipsMsg,{title:'请确定'},function(){
			$.post('<{:U('adBatchPass')}>', {batchId: idArray}, function(data) {;
				if (data.error) {
					layer.msg(data.errmsg,{icon:2});
				} else {
					layer.msg(data.errmsg,{icon:1,time:1000},function(){
						window.location.reload();
					});
				}
			});
		});
	} else {
		layer.msg('请选择要操作的项目',{icon:0});
	}
}

// 批量否决选择项
function selectVeto()
{
	var idArray = new Array;
	var subCount = 0;
	var subWait = 0;
	var subPass = 0;
	var subVeto = 0;
	$('.batchId').each(function(index, el) {
		if ($(this).prop('checked')) {
			// alert($(this).attr('data-status'));
			subCount++;
			switch ($(this).attr('data-status'))
			{
				case '1':
					subPass++;
					break;
				case '-1':
					subVeto++;
					break;
			}
			idArray[index] = $(this).val();
		};
	});
	var tipsMsg = '您确定审核<font color="red">禁止发布</font>所选的 '+subCount+' 广告？<br>其中：<font color="green">已通过</font>：'+subPass+'<br><font color="red">禁止发布</font>：'+subVeto+'<br>[请谨慎操作]';
	if (subCount) {
		layer.confirm(tipsMsg,{title:'请确定'},function(){
			$.post('<{:U('adBatchVeto')}>', {batchId: idArray}, function(data) {
				if (data.error) {
					layer.msg(data.errmsg,{icon:2});
				} else {
					layer.msg(data.errmsg,{icon:1,time:1000},function(){
						// window.location.href = "__SELF__";
						window.location.reload();
					});
				}
			});
		});
	} else {
		layer.msg('请选择要操作的项目',{icon:0});
	}
}
</script>

<include file="Public/footer" /> 